<%@ page import="com.yoooya.base.admin.utils.ShiroUtils" %>
<%@ page import="com.yoooya.base.model.po.system.UserInfoPo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>用户信息</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${ctxLayui}/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${ctxLayui}/layuiadmin/style/myStyle.css" media="all">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 10px 0 0;">

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">用户帐号<span style="color:red">*</span></label>
		<div class="layui-input-block">
			<input type="text" name="userName" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">姓名<span style="color:red">*</span></label>
		<div class="layui-input-block">
			<input type="text" name="name" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">昵称</label>
		<div class="layui-input-block">
			<input type="text" name="nickname"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">部门</label>
		<div class="layui-input-block">
			<div id="departmentTree" ></div>
			<input type="hidden" name="department" >
			<input type="hidden" name="departmentIds" >
		</div>
	</div>

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">角色</label>
		<div class="layui-input-block">
			<div id="roleIds"></div>
			<input type="hidden" name="roleIds"/>
			<input type="hidden" name="role"/>
		</div>
	</div>


	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">手机号<span style="color:red">*</span></label>
		<div class="layui-input-block">
			<input type="text" name="mobile" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">状态</label>
		<div class="layui-input-block">
			<select name="status"  id="status" lay-filter="status">
			</select>
		</div>
	</div>

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">密码</label>
		<div class="layui-input-block">
			<input type="text" name="password"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">岗位</label>
		<div class="layui-input-block">
			<input type="text" name="post"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>

	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">邮箱</label>
		<div class="layui-input-block">
			<input type="text" name="email"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">性别</label>
		<div class="layui-input-block">
			<select name="gender"  id="gender" lay-filter="gender">
			</select>
		</div>
	</div>



	<div class="layui-form-item layui-form-item-90" >
		<label class="layui-form-label">头像</label>
		<div class="layui-input-block">
			<div class="layui-upload">
				<button type="button" class="layui-btn" id="portrait-upload">上传图片</button>
				<img class="layui-upload-img" id="portrait-upload-img" style="width: 120px;" >
				<input type="hidden" name="portrait"/>
			</div>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">OpenId</label>
		<div class="layui-input-block">
			<input type="text" name="openId"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">微信号</label>
		<div class="layui-input-block">
			<input type="text" name="wechatNo"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">QQ</label>
		<div class="layui-input-block">
			<input type="text" name="qq"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>


	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">身份证</label>
		<div class="layui-input-block">
			<input type="text" name="idCard"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>


	<%--<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">加密盐</label>
		<div class="layui-input-block">
			<input type="text" name="salt"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>--%>


	<%--<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">数据权限</label>
		<div class="layui-input-block">
			<input type="text" name="permission"  placeholder="" autocomplete="off" class="layui-input">
		</div>
	</div>--%>


	<div class="layui-form-item layui-form-item-my" >
		<label class="layui-form-label">出生日期</label>
		<div class="layui-input-block">
			<input type="text" class="layui-input" name="birthday" id="birthday-laydate" placeholder="">
		</div>
	</div>


	<div class="layui-form-item layui-form-item-90" >
		<label class="layui-form-label">备注</label>
		<div class="layui-input-block">
			<textarea name="remark" placeholder="" class="layui-textarea"></textarea>
		</div>
	</div>
	<div class="layui-form-item layui-hide">
		<input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="添加">
		<input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="修改">
	</div>
</div>

<script src="${ctxLayui}/layuiadmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '${ctxLayui}/layuiadmin/'
	}).extend({
		index: 'lib/index'
	}).use(['index', 'form','dict','laydate','util','xmSelect','upload'], function(){
		var $ = layui.$ ,form = layui.form;
		var dict = layui.dict;
		var laydate = layui.laydate;
		var layutil = layui.util;
        var xmSelect = layui.xmSelect;
        var admin = layui.admin;
        var upload = layui.upload;
        var router = layui.router();

		var formData = window.parent.formData;

		//cjianquan 2020/2/9 单独表单页面
		var self = null;
		try{
            self = router.search.self;
            if(self==1){
                var userResp = admin.syncReq(ctx+'/system/login/info',{});
                if(userResp && userResp.data){
                    formData = userResp.data;
                    $.each(formData,function(item){
                        $("[name="+item+"]").val(formData[item]);
                    });
				}
			}
		}catch (err){
            self = null;
		}

        dict.setSelect("status","status",formData?formData.status:1);
        dict.setSelect("gender","sex",formData?formData.gender:1);

        var roleIds = formData?formData.roleIds:null;
        var roleXmSelect = xmSelect.render({
            el: '#roleIds',
            prop:{name:'name',value:'id'},
            data: [],
            on:function (data) {
                setTimeout(function () {
                    var valueStr = roleXmSelect.getValue("valueStr");
                    var nameStr = roleXmSelect.getValue("nameStr");
                    if(valueStr){
                        $("[name=roleIds]").val(valueStr)
                    }
                    if(nameStr){
                        $("[name=role]").val(nameStr)
                    }
                },500)

            }
        });

        var rtn = admin.syncReq(ctx+'/system/sysRole/queryByAll',{});
        if(rtn.code==0){
            roleXmSelect.update({
                data:rtn.data,
                autoRow:true,
            });
            if(roleIds){
                roleXmSelect.setValue(roleIds.split(","))
            }
        }


        //部门选择
        var departmentIds = formData?formData.departmentIds:null;
        var deptXmSelect = xmSelect.render({
            el: '#departmentTree',
            autoRow: true,
            filterable: true,
            tree: {
                show: true,
                showFolderIcon: true,
                showLine: true,
                indent: 20,
                expandedKeys: [],
                strict: false,
            },
            toolbar: {
                show: true,
                list: ['ALL', 'REVERSE', 'CLEAR']
            },
			prop:{
                name:'name',
				value:'id'
			},
            height: 'auto',
            data:[],
            on:function (data) {
                setTimeout(function () {
                    var valueStr = deptXmSelect.getValue("valueStr");
                    var nameStr = deptXmSelect.getValue("nameStr");
                    if(valueStr){
                        $("[name=departmentIds]").val(valueStr)
                    }
                    if(nameStr){
                        $("[name=department]").val(nameStr)
                    }
                },500)

            }
        })

        var deptResp = admin.syncReq(ctx+'/system/department/departmentTreeList',{});
        if(deptResp.code==0){
            var deptData = deptResp.data;
            deptXmSelect.update({
                data:deptData,
                autoRow:true,
            });
            if(departmentIds){
                deptXmSelect.setValue(departmentIds.split(","))
            }
		}

        var portrait = formData?formData.portrait:null;
        if(portrait){
            $('#portrait-upload-img').attr('src', portrait);
        }

        var uploadInst = upload.render({
            elem: '#portrait-upload'
            ,field:'picFile'
            ,data: {fileName:''} //请求上传的额外参数
            ,url: ctx+'/upload/img-upload'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#portrait-upload-img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.state !='SUCCESS'){
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#portrait-upload-img').attr('src', res.url);
                $("[name=portrait]").val(res.url)
            }
            ,error: function(){

            }
        });

		var birthday = formData?formData.birthday:null;
		var birthdayStr = birthday?layutil.toDateString(birthday):null
		laydate.render({
			elem: '#birthday-laydate',
			type: 'date',//type 默认为 date，所以可不填
			value:birthdayStr
		});

	})
</script>
</body>
</html>
